<?php
	/** php 发送流文件 
	* @param  String  $url  接收的路径 
	* @param  String  $file 要发送的文件 
	* @return boolean 
	*/  
	function sendStreamFile($url, $file){  
	    if(file_exists($file)){  
	        $opts = array(  
	            'http' => array(  
	                'method' => 'POST',  
	                'header' => 'content-type:application/x-www-form-urlencoded',  
	                'content' => file_get_contents($file)  
	            ),
	        );  
	        $context = stream_context_create($opts);  
	        $response = file_get_contents($url, false, $context);  
	        return $response;
	    }else{  
	        return false;  
	    }  
	}  
	//带图片流
	$ret = sendStreamFile('http://127.0.0.1/upload.php?getParam=oneParam','test.jpg');
	//带文本流
	$ret = sendStreamFile('http://127.0.0.1/upload.php?getParam=oneParam','test.txt');
	//输出反馈结果
	print_r($ret);


	//附：服务端接收CODE(简化版)
	function receiveStream(){
		 //原始数据
        $img_data = $GLOBALS['HTTP_RAW_POST_DATA'];
        if(empty($img_data)) {
            $img_data = file_get_contents('php://input');
        }
        
        //保存文件
        $filename = IMG_PATH . '/'. $imgId . IMG_TYPE;
        $result = @file_put_contents($filename,$img_data);	
	}

	//附：上传测试返回CODE
    function _uptest()
    {
        var_dump($_POST);
        echo "</br>";
        var_dump($_FILES);
        echo "</br>";
        var_dump($GLOBALS['HTTP_RAW_POST_DATA']);
        echo "</br>";
        var_dump(file_get_contents('php://input'));
        foreach ($_SERVER as $name => $value)
        {
            if (substr($name, 0, 5) == 'HTTP_')
            {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        var_dump($headers);
    }
